package com.zwan.oam_rtc.utils.messages;

import com.zwan.oam_rtc.utils.BytesUtils;
import com.zwan.oam_rtc.utils.wintcp.ByteTransfer;

import java.nio.ByteBuffer;

/***
 * 回调结果消息  
 * callflowId
 * callbackUrl
 * callstatus
 * @author 
 *
 */

public class SDFReqMessage extends AbstractStruct {
    
    private byte ReturnPattern;
    private byte ConnectNo;
    private byte ResultIndex;
    private byte[] SQLString = new byte[1024];
    private byte[] Event = new byte[2];
    private byte[] SplitChar = new byte[2];
    private byte[] DlgNumber = new byte[4];
    private byte DBNo;
    private byte[] TurnOver = new byte[4];


    private static int LENGTH = 1024 + 7 + 9;
    
    /**
     * 返回消息写入buffer
     */
    @Override
    public void writeToBuffer(ByteBuffer bf) {

        bf.put(ReturnPattern);
        bf.put(ConnectNo);
        bf.put(ResultIndex);
        bf.put(SQLString);
        bf.put(Event);
        bf.put(SplitChar);
        bf.put(DlgNumber);
        bf.put(DBNo);
        bf.put(TurnOver);
    }

    /**
     * buffer读出返回消息
     */
    @Override
    public void readFromBuffer(ByteBuffer bf) {
        ReturnPattern = bf.get();
        ConnectNo = bf.get();
        ResultIndex = bf.get();
        bf.get(SQLString);
        bf.get(Event);
        bf.get(SplitChar);
        bf.get(DlgNumber);
        DBNo = bf.get();
        bf.get(TurnOver);
    }

    public byte getReturnPatternVaule() {
        return ReturnPattern;
    }

    public byte getConnectNoVaule() {
        return ConnectNo;
    }

    public byte getResultIndexVaule() {
        return ResultIndex;
    }

    public String getSQLStringVaule() {
        return ByteTransfer.getString(SQLString);
    }

    public long getEventVaule() {
        short tmp = BytesUtils.getShort(Event);
        return Integer.reverseBytes(tmp)&0xFFFFL;
    }

    public String getSplitCharVaule() {
        return ByteTransfer.getString(SplitChar);
    }

    public long getDlgNumberVaule() {
        int tmp = BytesUtils.getInt(DlgNumber);
        return Integer.reverseBytes(tmp)&0xFFFFFFFFL;
    }

    public long getDBNoVaule() {
        return  DBNo&0xFFL;
    }


    public long getTurnOverVaule() {
        int tmp = BytesUtils.getInt(TurnOver);
        return Integer.reverseBytes(tmp)&0xFFFFFFFFL;
    }


    public byte getReturnPattern() {
        return ReturnPattern;
    }

    public byte getConnectNo() {
        return ConnectNo;
    }

    public byte getResultIndex() {
        return ResultIndex;
    }

    public byte[] getSQLString() {
        return SQLString;
    }

    public byte[] getEvent() {
        return Event;
    }

    public byte[] getSplitChar() {
        return SplitChar;
    }

    public byte[] getDlgNumber() {
        return DlgNumber;
    }

    public byte getDBNo() {
        return DBNo;
    }

    public byte[] getTurnOver() {
        return TurnOver;
    }

    @Override
    public int getLength() {
        return LENGTH;
    }



}
